package nGui.controls.menu;

import nGui.controls.Control;
import nGui.controls.menu.IMenu;

class Item extends Control, implements IMenu
{
	public var onClick(default,click) : Void -> Void;
	public var checked(getChecked,setChecked) : Bool;
	public var text(getText,setText) : String;
	private var __a : String;
	
	public function new( label : String )
	{
		super();
		__a = "ACTION";
		if ( label == "--" )
			this.__c = ngui_separator();
		else
			this.__c = ngui_item( untyped label.__s, neko.Lib.haxeToNeko( __a ) );
	}

	private function click( func : Void->Void )
	{
		Reflect.setField(this,"onClick",func);
		this.setCallback( this.__a, onClick, this.returnType );
		return func;
	}

	private function getChecked() : Bool
	{
		return ( getAttribute( "VALUE" ) == "ON" );
	}

	private function setChecked( val : Bool ) : Bool
	{
		if ( getAttribute( "VALUE" ) == "ON" )
			setAttribute( "VALUE", "OFF" );
		else
			setAttribute( "VALUE", "ON" );
		return null;
	}

	private function getText() : String
	{
		return getAttribute( "TITLE" );
	}

	private function setText( val : String ) : String
	{
		setAttribute( "TITLE", val );
		return null;
	}

	static var ngui_item = neko.Lib.load("nGui","ngui_element_item",2);
	static var ngui_separator = neko.Lib.load("nGui","ngui_element_separator",0);
}
